USE AdventureWorks2008

--Create a user-defined function

CREATE FUNCTION fnSquared 
(
	@number int
)
RETURNS int
AS
BEGIN
	DECLARE @result int
	SET @result = @number * @number
	RETURN @result
END
GO

--Query a user-defined function

SELECT dbo.fnSquared(2)
SELECT dbo.fnSquared(8)

